﻿using System;
using System.Diagnostics.Contracts;

namespace DaveSexton.Labs
{
	internal sealed class ProxyLab : Lab
	{
		#region Public Properties
		public override string SourceCode
		{
			get
			{
				return ActualLab.SourceCode ?? base.SourceCode;
			}
		}

		public override string SourceXaml
		{
			get
			{
				return ActualLab.SourceXaml ?? base.SourceXaml;
			}
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ProxyLab" /> class.
		/// </summary>
		public ProxyLab(ILab lab)
			: base(lab)
		{
			Contract.Requires(lab != null);
			Contract.Ensures(IsProxy);
			Contract.Ensures(ActualLab == lab);
		}
		#endregion

		#region Methods
		[ContractInvariantMethod]
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
		private void ObjectInvariant()
		{
			Contract.Invariant(IsProxy);
		}

		protected override void Main()
		{
			throw new NotSupportedException();
		}

		public override string FormatSourceCode(string source)
		{
			return ActualLab.FormatSourceCode(source) ?? base.FormatSourceCode(source);
		}

		public override string FormatSourceXaml(string source)
		{
			return ActualLab.FormatSourceXaml(source) ?? base.FormatSourceXaml(source);
		}
		#endregion
	}
}